const path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var WebpackDevServer = require('webpack-dev-server');
var options = {
  mode: 'development',
  context: process.cwd(),
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {},
  plugins: [
    new HtmlWebpackPlugin({
      template: './dist/index.html', //指定模板文件
      filename: 'index.html', //产出后的文件名
      inject: false,
      hash: true, //为了避免缓存，可以在产出的资源后面添加hash值

    }),
  ],
  devServer: {
    port: 8080
  }
}

 var compiler = webpack(options);
 var server = new WebpackDevServer(compiler);
 server.listen(8080);